
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 页面路由

/// 页面进入无动画
class NoAnimRouteBuilder extends PageRouteBuilder {
  final Widget page;

  NoAnimRouteBuilder(this.page)
      : super(
      opaque: false,
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: Duration(milliseconds: 0),
      transitionsBuilder:
          (context, animation, secondaryAnimation, child) => child);
}

/// 页面渐变进入
class FadeRouteBuilder extends PageRouteBuilder {
  final Widget page;

  FadeRouteBuilder(this.page)
      : super(
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: Duration(milliseconds: 800),
      transitionsBuilder: (context, animation, secondaryAnimation,
          child) =>
          FadeTransition(
            opacity: Tween(begin: 0.1, end: 1.0).animate(CurvedAnimation(
              parent: animation,
              curve: Curves.fastOutSlowIn,
            )),
            child: child,
          ));
}

/// 顶部进入动画
class SlideTopRouteBuilder extends PageRouteBuilder {
  final Widget page;

  SlideTopRouteBuilder(this.page)
      : super(
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: Duration(milliseconds: 800),
      transitionsBuilder:
          (context, animation, secondaryAnimation, child) =>
          SlideTransition(
            position: Tween<Offset>(
                begin: Offset(0.0, -1.0), end: Offset(0.0, 0.0))
                .animate(CurvedAnimation(
                parent: animation, curve: Curves.fastOutSlowIn)),
            child: child,
          ));
}

/// 缩放进入动画
class ScaleRouteBuilder extends PageRouteBuilder {
  final Widget page;

  ScaleRouteBuilder(this.page)
      : super(
    pageBuilder: (context, animation, secondaryAnimation) => page,
    transitionDuration: Duration(milliseconds: 800),
    transitionsBuilder: (context, animation, secondaryAnimation, child) =>
        ScaleTransition(
          scale: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
              parent: animation, curve: Curves.fastOutSlowIn)),
          child: child,
        ),
  );
}

// iOS 风格的页面进入，一般是从右侧进入
class CupertinoRouteBuilder extends CupertinoPageRoute {
  final Widget page;

  CupertinoRouteBuilder(this.page):super(
    builder:(context) => page,
  );

}

// Material (Android) 风格的页面进入，一般...我也不知道，看不出来
class MaterialRouteBuilder extends MaterialPageRoute {
  final Widget page;

  MaterialRouteBuilder(this.page):super(
    builder: (context) => page,
  );

}
